//导航选择器
function navMenuClick(){
    var url = window.location.href;
    if (url.indexOf("dashboard") > 0 ) {
        $("#dashboard").addClass("active");
    }else if (url.indexOf("roleManage") > 0 || url.indexOf("roleEdit") > 0 || url.indexOf("roleConfigAuthorityGetEntity") > 0) {
        $("#systemConfig").addClass("active");
        $("#roleManage").addClass("active");
    } else if (url.indexOf("userManage") > 0 || url.indexOf("userEdit") > 0) {
        $("#systemConfig").addClass("active");
        $("#userManage").addClass("active");
    } else if (url.indexOf("authorityManage") > 0 || url.indexOf("authorityEdit") > 0) {
        $("#systemConfig").addClass("active");
        $("#authorityManage").addClass("active");
    }else if (url.indexOf("dictionaryManage") > 0 || url.indexOf("dictionaryEdit") > 0) {
        $("#dictionaryManage").addClass("active");
        $("#tilesManage").addClass("active");
    }else if (url.indexOf("logManage") > 0 ) {
        $("#logManage").addClass("active");
        $("#tilesManage").addClass("active");
    }else if (url.indexOf("mapManage") > 0 ) {
        $("#mapConfig").addClass("active");
        $("#mapManage").addClass("active");
    }else if (url.indexOf("socketManage") > 0 ) {
        $("#mapConfig").addClass("active");
        $("#socketManage").addClass("active");
    }else if (url.indexOf("indoorMapManage") > 0 ) {
        $("#mapConfig").addClass("active");
        $("#indoorMapManage").addClass("active");
    }else if (url.indexOf("tilesManage") > 0 || url.indexOf("tilesEdit") > 0) {
        $("#baseConfig").addClass("active");
        $("#tilesManage").addClass("active");
    }
}

// 提示条配置
/*toastr.options = {
	"closeButton" : true,
	"debug" : false,
	"progressBar" : true,
	"preventDuplicates" : false,
	"positionClass" : "toast-top-right",
	"onclick" : null,
	"showDuration" : "400",
	"hideDuration" : "1000",
	"timeOut" : "7000",
	"extendedTimeOut" : "1000",
	"showEasing" : "swing",
	"hideEasing" : "linear",
	"showMethod" : "fadeIn",
	"hideMethod" : "fadeOut"
}*/
//Form表单格式化
/*var info = $('#temp_form').serializeObject();
info["id"]=id;
info["name"]=name;
var jsonrtinfo = JSON.stringify(info);*/
$.fn.serializeObject = function() {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [ o[this.name] ];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

//获取Session信息
var currentSelectTiles=null;
$(document).ready(function() {
    $.ajax({
        type: "POST",
        url: "getSessionInfo",
        contentType: "application/json; charset=utf-8",
        async:false,
        success: function(data){
            if(data.userAuthority!=null){
                $("#side-menu").append(data.userAuthorityNavHtml);
                currentSelectTiles=data.currentSelectTiles;
            }else{
                //window.location.href="../zhsq/login";
            }
            if(data.user!=null){
                document.getElementsByTagName('b')[0].innerHTML=data.user.realName;
                document.getElementsByTagName('b')[1].innerHTML=data.user.realName;
            }else{
                window.location.href="../zhsq/login";
            }
        },
        error: function(){
            alert("系统异常！");
        }
    });
    $("#side-menu").metisMenu();
    navMenuClick();
})

function showHideChildMenu(obj){
    var aID=obj.id;
    var ulID=aID.replace("a","ul");
    if($("#"+ulID).hasClass("collapse")){
        $("#"+ulID).removeClass("collapse");
    }else{
        $("#"+ulID).addClass("collapse");
    }
}



//告警声音通知
//告警声音
var waringSoundTimer=null;
var warningMp3Path="/zhsq/userfiles/points/sound/warning.mp3";
var audio = document.createElement("audio");
audio.src = warningMp3Path;
function warningSoundMp3Stop(){
    audio.pause();// 暂停
}
function warningSoundMp3Start(){
    audio.play();// 播放
}
if(!audio.paused){
    warningSoundMp3Stop();
}

//wobsocket 连接
var dwgaojwebsocket = null;
//判断当前浏览器是否支持WebSocket
if ('WebSocket' in window) {
    dwgaojwebsocket = new WebSocket("ws://192.168.1.11:8081/websocket/message");
   // websocket = new WebSocket('ws://192.168.17.11:8081/zhsq/websocket/mysocket');
}else {
    alert('当前浏览器不支持WebSocket!');
}

//连接发生错误的回调方法
dwgaojwebsocket.onerror = function () {
    setDwgaojMessageInnerHTML("WebSocket连接发生错误");
};

//连接成功建立的回调方法
dwgaojwebsocket.onopen = function () {
    //setDwgaojMessageInnerHTML("WebSocket连接成功");
    dwgaojwebsocket.send("测试消息");
}

//接收到消息的回调方法
dwgaojwebsocket.onmessage = function (event) {
    console.info("接收到消息的回调信息："+event.data);
    if(event.data=="true"){
        warningSoundMp3Start();
    }else{
        warningSoundMp3Stop();
    }
    //setMessageInnerHTML(event.data);
}

//连接关闭的回调方法
dwgaojwebsocket.onclose = function () {
    setDwgaojMessageInnerHTML("WebSocket连接关闭");
}

//监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
window.onbeforeunload = function () {
    closeDwgaojWebSocket();
}

//将消息显示在网页上
function setDwgaojMessageInnerHTML(innerHTML) {
    console.info(innerHTML);
}
//关闭socket
function closeDwgaojWebSocket() {
    dwgaojwebsocket.close();
}
//清空
function clearDwgaoj(){
    document.getElementById('message').innerHTML="";
}

//发送消息
function sendDwgaoj() {
    var message = document.getElementById('text').value;
    dwgaojwebsocket.send(message);
}


//开始全屏
function fullScreen()
{
    var docElm = document.documentElement;
    if (docElm.requestFullscreen) {
        docElm.requestFullscreen();
    }
    //FireFox
    else if (docElm.mozRequestFullScreen) {
        docElm.mozRequestFullScreen();
    }
    //Chrome等
    else if (docElm.webkitRequestFullScreen) {
        docElm.webkitRequestFullScreen();
    }
    //IE11
    else if (docElm.msRequestFullscreen) {
        docElm.msRequestFullscreen();
    }
}

//退出全屏
function exitFullScreen() {
    if (document.exitFullscreen) {
        document.exitFullscreen();
    }
    else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
    }
    else if (document.webkitCancelFullScreen) {
        document.webkitCancelFullScreen();
    }
    else if (document.msExitFullscreen) {
        document.msExitFullscreen();
    }
}

//事件监听
document.addEventListener("fullscreenchange", function () {
    fullscreenState.innerHTML = (document.fullscreen) ? "" : "not ";
}, false);

document.addEventListener("mozfullscreenchange", function () {
    fullscreenState.innerHTML = (document.mozFullScreen) ? "" : "not ";
}, false);

document.addEventListener("webkitfullscreenchange", function () {
    fullscreenState.innerHTML = (document.webkitIsFullScreen) ? "" : "not ";
}, false);

document.addEventListener("msfullscreenchange", function () {
    fullscreenState.innerHTML = (document.msFullscreenElement) ? "" : "not ";
}, false);







